using System;
using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using Spaanjaars.ContactManager.Infrastructure.Domain;
using Spaanjaars.ContactManager.Infrastructure.Validation;

namespace Spaanjaars.ContactManager.Model
{
    public class Address : ValueObject<Address>
    {
        private Address()
        {
                
        }

        public Address(string houseNumber, string street, string zipCode, string city, string country)
        {
            HouseNumber = houseNumber;
            Street = street;
            ZipCode = zipCode;
            City = city;
            Country = country;

            Check.ThrowExceptionIfAnyBrokenRules(this, "Address construction");
        }

        public string HouseNumber { get; private set; }

        public string Street { get; private set; }

        public string ZipCode { get; private set; }

        public string City { get; private set; }

        public string Country { get; private set; }

        public ContactPerson ContactPerson { get; set; }        
                
        public override string ToString()
        {
            return String.Format("{0} {1}, {2}, {3}, {4}", HouseNumber, Street, City, ZipCode, Country);
        }

        public override IEnumerable<IBrokenRule> GetBrokenRulesFor(IDomainObjectValidator<Address> domainObjectValidator)
        {
            return domainObjectValidator.RulesBrokenBy(this);            
        }

        public override IEnumerable<IBrokenRule> GetBrokenRules()
        {
            return GetBrokenRulesFor(new AddressValidator());
        }
    }
}